#!/bin/bash

if [ $# -ne 2 ] # if number of is not equal to 2 
    then
    echo "\n";
    echo "ERROR: missing form command line arguments."
    echo "USAGE: $> sh makeBinnedSpect.sh [binned data root name] [number of bins (0 to Nbin)]"
    echo ""
    echo "     eg. sh scripts/makeBinnedSpect.sh speeds_dat 33"
    echo "\n";
    exit 1
fi

# CHANGE THESE FOR EACH SET OF BINS!
###################################
DATAROOTNAME=$1
NBINS=$2
echo "echo \"#=====================================================\""
echo "echo \"#root name      = $DATAROOTNAME\""
echo "echo \"#number of bins = $NBINS\""
echo "echo \"#=====================================================\""
###################################


DATADIR="bins4_synth_split/"
OUTDIR="spectra/"
BINNAME="-bin"
DATATYPE=".dat"
CLEAN_BIN="./cleanPP"


run_cleanPP () {
#    echo "${CLEAN_BIN} -i=$1 -o=$2 -g=0.02 -l=10000 -n=8\n"
#    echo "${CLEAN_BIN} -i=$1 -o=$2 -g=0.02 -l=7000 -n=8\n"
    echo "${CLEAN_BIN} -i=$1 -o=$2 > ${2}_clean.log\n"
    #$CLEAN_BIN -i=$1 -o=$2
}

N=0
while [ $N -le $NBINS ]
  do
  echo "echo \"#- running clean >> BIN$N << \""
  echo "#----------------------------"
  CLEANDATA=${DATADIR}${DATAROOTNAME}${BINNAME}${N}${DATATYPE}
  CLEANOUTDIR=${OUTDIR}${DATAROOTNAME}${BINNAME}${N}
  echo "#data   = ${CLEANDATA}"
  echo "#output = ${CLEANOUTDIR}"
  run_cleanPP ${CLEANDATA} ${CLEANOUTDIR}
  N=$(($N+1))
done

